using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using NUnit.Framework;
using sbMembership.Library.Presenters;

namespace Tests.sbMembership.EditUser
{
    [TestFixture]
    public class EditUserTest
    {

        private MockEditUserView mockView;
        private EditUserPresenter presenter;
        private bool editUserCompleteEventRaised;

        [TestFixtureSetUp]
        public void Setup()
        {
            mockView = new MockEditUserView();
            presenter = new EditUserPresenter(mockView);
            mockView.AttachPresenter(presenter);
        }

        [Test]
        public void InitView()
        {
            presenter.InitViewForEditing(TestSetup.testEditUserName, false);
            Assert.AreEqual(mockView.UserToUpdate.UserName, TestSetup.testEditUserName);
        }

        [Test]
        public void EditUser()
        {
            presenter.InitViewForEditing(TestSetup.testEditUserName, false);
            presenter.EditUserCompleteEvent = new EventHandler(OnEditUserCompleteEvent);
            mockView.UserToUpdate.Email = TestSetup.testEditUserName + "@test.com";
            presenter.SaveUser();
            MembershipUser testUser = Membership.GetUser(TestSetup.testEditUserName);
            Assert.IsNotNull(testUser);
            Assert.AreEqual(testUser.Email, TestSetup.testEditUserName + "@test.com");
            Assert.IsTrue(editUserCompleteEventRaised);
        }

        void OnEditUserCompleteEvent(object sender, EventArgs e)
        {
            editUserCompleteEventRaised = true;
        }

    }
}
